<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>作者注册界面</title>
</head>
<script type="text/javascript" src="../../js/jquery-3.6.0.min.js"></script>
<style>
    body{
        background-image: url(../../img/authorBac.jpg);
        background-repeat: no-repeat;
        width: 100%;
        height: 100%;
    }
</style>
<div th:include="common/style"></div>
<body>
<form class="authorRegister">
    <input type="hidden" name="uRoleid" value="3">
    <table>
        <tr>
            <td>
                <h2>注册成为作者</h2>
            </td>
            <td style="text-align: right; font-size: small;">
                已是作者？<a th:href="@{toLoginAuthor}">直接登录</a>
            </td>
        </tr>
        <tr>
            <td style="text-align: right"><font color="red">*</font>手机号</td>
            <td>
                <input type="tel" name="uTel" id="utel">
            </td>

        </tr>
        <tr>
            <td style="text-align: right">作者笔名</td>
            <td>
            <input type="text" name="uName">
                <span id="sp1"></span>
            </td>
        </tr>
        <tr>
            <td style="text-align: right"><font color="red">*</font>真实姓名</td>
            <td>
            <input type="text" name="uRealname">
            </td>
        </tr>
        <tr>
            <td style="text-align: right"><font color="red">*</font>身份证号</td>
            <td>
            <input type="tel" name="uIdnum" id="uidnum">
            </td>
        </tr>
        <tr>
            <td style="text-align: right"><font color="red">*</font>QQ</td>
            <td>
            <input type="text" name="uQq">
            </td>
        </tr>
        <tr>
            <td style="text-align: right"><font color="red">*</font>设置密码</td>
            <td>
            <input type="password" id="upwd1">
            </td>
        </tr>
        <tr>
            <td style="text-align: right"><font color="red">*</font>确认密码</td>
            <td>
            <input type="password" name="uPwd" id="upwd2" onblur="checkPwd()">
            </td>
        </tr>
    </table>
    <table>
        <tr>
            <td colspan="2">
                <font color="red" size="2">
                    重要提示：<br>
                    1、请确保手机号、真实姓名、身份证号是您本人的真实信息，否则无法创建作品。<br>
                    2、建议手机号与您签约银行卡的预留手机号保持一致，否则无法发放稿费。
                </font>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="font-size: small">
                <input type="checkbox" id="read">
                我已阅读并同意
                <a th:href="@{agreement}" target="_blank">《用户协议》</a>
                <a th:href="@{agreement}" target="_blank"> 《隐私协议》</a>
                <a th:href="@{agreement}" target="_blank">《原创作品登载规则和服务约定》</a>
            </td>
        </tr>
        <tr>
            <td colspan="2" class="cen">
                <input type="button" value="成为作者" onclick="checkAll()" class="btn-primary">
            </td>
        </tr>
    </table>
</form>
</body>
<script>
    function checkDel(){
        var tel = /^[0-9]{11}$/;
        if(tel.test($("#utel").val())){
            return true;
        }else {
            return false;
        }
    }

    function checkIdnum(){
        var idnum = /^[0-9]{18}$/;
        if (idnum.test($("#uidnum").val())){
            return true;
        }else {
            return false;
        }
    }

    function checkPwd(){
        var pwd1 = $("#upwd1").val();
        var pwd2 = $("#upwd2").val();
        if (pwd1 == pwd2){
            return true;
        }else {
            alert("两次密码输入不一致，请检查，重新输入")
        }
    }

    function checkAll(){
        var f1 = checkDel();
        var f2 = checkIdnum();
        var f3 = checkPwd();
        if ($("#read:checked").val()){
            if (f1 && f2 && f3){
                $.ajax({
                    url:"addUser",
                    type:"post",
                    dataType:"text",
                    data:$("form").serialize(),
                    success:function (data){
                        if (data == 1){
                            $("#sp1").html("<font color='red' size='2'>!该用户名已被注册，请更换</font>")
                        }
                        if (data == "success"){
                            alert("注册成功");
                            location.href = "toLoginAuthor";
                        }
                    },error:function (){
                        alert("注册失败-用户名已被注册，请更换尝试");
                    }
                })
            }else {
                alert("输入信息有不合法内容，请检查")
                return false;
            }
        }else {
            alert("请勾选权益须知");
            return false;
        }
    }
</script>
</html>